﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OCRTheNewHope
{
    static class ShiftDBCreater
    {
        public static Digit[] CreateDB(int startingDigitID, Digit[] digits, int[] offsets)
        {
            Digit[] rVal = new Digit[digits.Length];

            for (int i = 0; i < digits.Length; i++)
            {
                rVal[i] = Shift(startingDigitID, digits[i], offsets[0], offsets[1]);
                startingDigitID++;
            }

            return rVal;
        }

        private static Digit Shift(int digitID, Digit digit, int v, int h)
        {
            byte[,] image = digit.OriginalGrayscaleMatrix;
            byte[,] rVal = new byte[image.GetLength(0), image.GetLength(1)];

            for (int i = 0; i < rVal.GetLength(0); i++)
            {
                for (int j = 0; j < rVal.GetLength(1); j++)
                {
                    int ii = i + h;
                    int jj = j + v;

                    if (ii > -1 && jj > -1 && ii < rVal.GetLength(0) && jj < rVal.GetLength(1)) // if it's in the image
                    {
                        rVal[ii, jj] = image[i, j];
                    }
                }
            }

            return new Digit(digitID, digit.DigitValue, rVal);
        }
    }
}
